<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">

    <title>匠心指数</title>

    <meta name="keywords" content="">
    <meta name="description" content="">

    <!--[if lt IE 9]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->

    <link rel="shortcut icon" href="favicon.ico"> <link href="__STATIC__/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__STATIC__/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="__STATIC__/css/animate.css" rel="stylesheet">
    <link href="__STATIC__/css/style.css?v=4.1.0" rel="stylesheet">
    <style type="text/css">
        th,td{
            text-align: center;
            width: 9%;
        }
        body{
            text-align: center;
        }
        input{
            text-align: center;
        }
    </style>
</head>
<body>
<h1>匠心指数</h1>

<form class="form-horizontal m-t" id="signupForm" action="{:url('showJren')}" method="post" enctype="multipart/form-data">
    <div class="form-group" style="text-align: center; margin: 0 auto;">
        <label class="col-sm-1 control-label">茶类</label>
        <div class="col-sm-2">
            <select class="form-control m-b " name="teacase" style="font-size: 12px;">
                <option value="10000" {if $currentteacase==10000}selected="selected" {/if}>查看全部</option>
                {foreach $teacase as $case}
                <option value="{$case['id']}" {if $currentteacase==$case['id']}selected="selected" {/if}>{$case['teaname']}</option>
                {/foreach}
                <option value="9999" {if $currentteacase==9999}selected="selected" {/if}>其它</option>
            </select>
        </div>

        <label class="col-sm-1 control-label">产区</label>
        <div class="col-sm-2">
            <select class="form-control m-b" name="teaarea" style="font-size: 12px;">
                <option value="10000" {if $currentteaarea==10000}selected="selected"{/if}>查看全部</option>
                {if $areas}
                {foreach $areas as $a}
                <option value="{$a.id}" {if $a.id==$currentteaarea}selected="selected"{/if}>{$a.area}</option>
                {/foreach}
                {/if}
                <option value="9999" {if $currentteaarea==9999}selected="selected"{/if}>其它</option>
            </select>
        </div>
        <div class="col-sm-2">
            <button class="btn btn-primary" type="submit">提交</button>
        </div>
    </div>
</form>


<div class="ibox-content" style="width:90%;margin: 0 auto;">
{if $data}
    <table class="table table-bordered" >
        <thead>
            <tr>
                <th>排名</th>
                <th>姓名</th>
                <th>茶类</th>
                <th>产地</th>
                <th>茶人传</th>
                <th>前端显示得分</th>
                <th>计算后得分</th>
                <th>随机分数</th>
                <th>加分</th>
                <th>减分</th>
                <th>上榜</th>
            </tr>
        </thead>
        <tbody>
            {foreach $data as $d}
            <tr index = '{$d.id}'>
                <td style="width: 5%;">{$d.rank}</td>
                <td>{$d.name}</td>
                <td>{$d.teacase}</td>
                <td>{$d.teaarea}</td>
                {if($d.biography==1)}
                <td><input type="checkbox" name="biography" value="1" index = "{$d.id}" checked></td>
                {else /}
                <td><input type="checkbox" name="biography" value="0" index = "{$d.id}" ></td>
                {/if}
                <td class="score" id="{$d.id}">{$d.score}</td>
                <td class="acpoint" acpoint="{$d.id}" >{$d.total_point}</td>
                <td style="width: 5%;"><input type="" name="random" value="{$d.random}"></td>
                <td><button class="modify" index = "{$d.id}" status="1">加分</button></td>
                <td><button class="modify" index = "{$d.id}" status="0">减分</button></td>
                {if $d.bangdan_id==1}
                <td>
                    <button class="YoN" indexm="{$d['id']}" value="4">是</button>
                </td>
                {else /}
                <td><button class="YoN" indexm="{$d['id']}" value="1" style="color: red;">否</button></td>
                {/if}
            </tr>
            {/foreach}
        </tbody>
    </table>
    <form action="{:url('updateAll')}">
        <button " data-toggle="modal"  data-target="#delmod" style="display: none;">同步数据</button>
    </form>
    <div style="color: red;display: none;">同步数据将会把前端显示的得分全部变更会计算后得分，手动修改的分数将会清0</div>
</div>
{/if}



<!-- 全局js -->
<script src="__STATIC__/js/jquery.min.js?v=2.1.4"></script>
<script src="__STATIC__/js/bootstrap.min.js?v=3.3.6"></script>
<script type="text/javascript">
    //修改按钮
    $(".modify").click(function(){
        var url = "{:url('modify')}";
        var id = $(this).attr("index");
        var score = $(this).parents("tr").find(".score").html();
        var randompoint = $(this).parents("tr").find("input[name=random]").val();
        var status = $(this).attr('status');
        if(parseInt(randompoint)>=3000){
            randompoint = 3000;
        }
        var newscore;
        if(status==1){
            newscore = parseInt(randompoint) + parseInt(score);
        }else{
             newscore = parseInt(score) - parseInt(randompoint);
             if(newscore<0){
                newscore=0;
             }
        }
        var data = {
            id:id,
            newscore:newscore,
        };
        $.post(url,data,function(data){
            $("td[id="+id+"]").html(data);
            alert("修改成功")
        })
    })

    //选择框
    $("select[name=teacase] ").change(function(){
        var val = $(this).find("option:selected").attr("value");
        if(val == 10000){
            var inner = "<option value="+10000+">查看全部</option>";
            $("select[name=teaarea]").html(inner);
            exit();
        }
        if(val == 9999){
            var a = "<option value="+9999+">其它</option>";
            $("select[name=teaarea]").html(a);
            exit();
        }

        var url="{:url('reTeaAreaJson')}";
        $.post(url, {teacase_id:val},function(data){
            var areas = JSON.parse(data);
            var option="<option value='10000'>查看全部</option>";
            for(index in areas){
                var a = "<option value="+areas[index]['id']+">"+areas[index]['area']+"</option>"
                option +=a;
            }
            option += "<option value='9999'>其它</option>";
            $("select[name=teaarea]").html(option)
        })
    })

    //茶人传
    $('input[name= biography]').click(function(){
        var mark = $(this).attr('value');
        var id = $(this).attr('index');
        var score = parseInt($(this).parents("tr").find(".score").html());
        var acpoint = parseInt($(this).parents("tr").find(".acpoint").html());
        var url = "{:url('havebiography')}";

        if(mark==1){
            score = score - 10000;
            acpoint = acpoint -10000;
            var data ={
                id:id,
                score:score,
                biography:0
            };

            $.post(url,data,function(data){
                if(data==1){
                    $('input[index='+id+']').attr('value',0)
                    $("td[id="+id+"]").html(score);
                    $("td[acpoint="+id+"]").html(acpoint);
                    alert('修改成功')
                }
            })
        }else{
            score = score + 10000;
            acpoint = acpoint + 10000;
            var data ={
                id:id,
                score:score,
                biography:1
            };
            $.post(url,data,function(data){
                if(data==1){
                    $('input[index='+id+']').attr('value',1)
                    $("td[id="+id+"]").html(score);
                    $("td[acpoint="+id+"]").html(acpoint);
                    alert('修改成功')
                }
            })
        }
    })


    $('.YoN').click(function(){
        var url = "{:url('entries/Jren/shangbang')}";
        var a = $(this).html();
        var id = $(this).attr("indexm");
        var bangdan_id = $(this).attr("value");
        var data = {
            id:id,
            bangdan_id:bangdan_id
        }
        $.post(url,data,function(data){
            if(data == 1){
                if(a=="是"){
                    $('button[indexm='+id+']').html("否");
                    $('button[indexm='+id+']').attr('value',1);
                    $('button[indexm='+id+']').attr('style',"color: red;");
                }else{
                    $('button[indexm='+id+']').html("是");
                    $('button[indexm='+id+']').attr('value',4);
                    $('button[indexm='+id+']').attr('style',"color: none;");
                }
                alert('修改成功');
            }
        })
   })


</script>
</body>
</html>